
clear all

*** Descriptive statistics *****************************************************
********************************************************************************

cd "$root"
use "Data/data_candidates.dta"
cd "$output"

*** Candidate characteristics ***
local numbers " & (1) & (2) & (3) & (4) & (5) & (6) & (7) & (8) \\ \midrule"
estpost tabstat r_age r_ed_uni r_ran_before r_gov_job_before r_NGO r_adv r_expenditure r_radio_yes, statistics(mean) by(cand_type) nototal
esttab using "Table 1.tex", replace cells("r_age(fmt(1) label(\specialcell{Age})) r_ed_uni(fmt(2) label(\specialcell{University\\educated})) r_ran_before(fmt(2) label(\specialcell{Ran\\before})) r_gov_job_before(fmt(2) label(\specialcell{Govt. job\\before})) r_NGO(fmt(2) label(\specialcell{NGO job\\before})) r_adv(fmt(2) label(\specialcell{Advocacy\\experience})) r_expenditure(fmt(%9.0fc) label(\specialcell{Campaign\\expenditure})) r_radio_yes(fmt(2) label(\specialcell{Radio\\station}))") noobs nomtitle nonumber posthead("`numbers'") f

*** Candidate attitudes towards policy promises ***
local numbers " & (1) & (2) & (3) \\ \midrule"
estpost tabstat e_prom_diff e_prom_rally e_prom_radio, statistics(mean) by(cand_type) nototal
esttab using "Table 2.tex", replace cells("e_prom_diff(fmt(2) label(\specialcell{Different\\promises})) e_prom_rally(label(\specialcell{Rally\\credibility})) e_prom_radio(label(\specialcell{Radio\\credibility}))") noobs nomtitle nonumber posthead("`numbers'") f

*** Reasons cited for debate participation ***
local numbers " & (1) & (2) & (3) & (4) & (5) & (6) \\ \midrule"
estpost tabstat why_duty why_policy why_comp why_publicity why_radio why_attack, statistics(mean) by(cand_type) nototal
esttab using "Table 3.tex", replace cells("why_duty(fmt(2) label(\specialcell{Duty}))  why_policy(label(\specialcell{Policies}))  why_comp(label(\specialcell{Competence}))  why_publicity(label(\specialcell{Publicity})) why_radio(label(\specialcell{Radio})) why_attack(label(\specialcell{Attack}))") noobs nomtitle nonumber posthead("`numbers'") f

cd "$root"
use "Data/data_transcript.dta"
cd "$output"

*** Transcript descriptive statistics ***
local numbers " & (1) & (2) & (3) & (4) & (5) & (6) & (7) \\ \midrule"
estpost tabstat intro_words emph_education emph_experience words_cdf words_lsp attacked attacker, statistics(mean) by(cand_type) nototal
esttab using "Table 4.tex", replace cells("intro_words(fmt(1) label(\specialcell{Intro\\words})) emph_education(fmt(2) label(\specialcell{Education\\emphasis})) emph_experience(fmt(2) label(\specialcell{Experience\\emphasis})) words_cdf(label(\specialcell{CSDF\\words}) fmt(1)) words_lsp(label(\specialcell{LSP\\words}) fmt(1)) attacked(fmt(2) label(\specialcell{Attacked})) attacker(fmt(2)  label(\specialcell{Attacker}))") noobs nomtitle nonumber posthead("`numbers'") f


*** Balance tables  ************************************************************
********************************************************************************

*** Candidate-level balance ***

cd "$root"
use "Data/data_candidates.dta"
cd "$output"

foreach var in took_survey r_age r_ed_uni r_radio_yes r_male r_ran_before r_gov_job_before r_adv r_NGO party_UP pref_match_share perf_pred {
	
	* Unweighted specifications *
	eststo `var': cap qui areg `var' i.t_invite, absorb(t_block) cluster(EDCODE)
		qui estadd local Weight "No"
		qui sum `var' if e(sample)==1 & t_invite==0
		qui estadd scalar Control_Mean = `r(mean)'
	eststo i_`var': cap qui areg `var' i.t_invite if incumbent==1, absorb(t_block) cluster(EDCODE)
		qui estadd local Weight "No"
		qui sum `var' if e(sample)==1 & t_invite==0
		qui estadd scalar Control_Mean = `r(mean)'
	eststo c_`var': cap qui areg `var' i.t_invite if top_chal==1, absorb(t_block) cluster(EDCODE)
		qui estadd local Weight "No"
		qui sum `var' if e(sample)==1 & t_invite==0
		qui estadd scalar Control_Mean = `r(mean)'
	
	* Weighted specifications *
	eststo `var'_w1: cap qui areg `var' i.t_invite [aweight=1/wgt_all], absorb(t_block) cluster(EDCODE)
		qui estadd local Weight "1/Cand"
		qui sum `var' [aweight=1/wgt_all] if e(sample)==1 & t_invite==0
		qui estadd scalar Control_Mean = `r(mean)'
	eststo c_`var'_w1: cap qui areg `var' i.t_invite if top_chal==1 [aweight=1/wgt_chal], absorb(t_block) cluster(EDCODE)
		qui estadd local Weight "1/Chal"
		qui sum `var' [aweight=1/wgt_chal] if e(sample)==1 & t_invite==0
		qui estadd scalar Control_Mean = `r(mean)'
}

local titles "& Response & Age & Univ ed & Radio & Male & Ran before & Gov job & Advocacy & NGO & \specialcell{Party: UP} & \specialcell{Policy\\alignment} & \specialcell{Debate\\performance} \\"
local numbers " & (1) & (2) & (3) & (4) & (5) & (6) & (7) & (8) & (9) & (10) & (11) & (12) \\ \midrule"

esttab took_survey r_age r_ed_uni r_radio_yes r_male r_ran_before r_gov_job_before r_adv r_NGO party_UP pref_match_share perf_pred using "Table A11.tex", ///
	replace nonumber refcat(1.t_invite "\textbf{A. All candidates}", nolabel) ///
	nomtitles posthead("`titles'" "`numbers'") b(3) se label alignment(S) f nomtitles nogaps booktabs scalars("Control_Mean \hspace{0.1cm} Control Mean" "N \hspace{0.1cm} Observations") noobs sfmt(2 %9.0fc 0) compress nostar nobaselevels keep(1.t_invite)
esttab i_took_survey i_r_age i_r_ed_uni i_r_radio_yes i_r_male i_r_ran_before i_r_gov_job_before i_r_adv i_r_NGO i_party_UP i_pref_match_share i_perf_pred using "Table A11.tex", ///
	append nonumber refcat(1.t_invite "\textbf{C. Incumbents}", nolabel) ///
	nomtitles b(3) se label alignment(S) f nomtitles nogaps booktabs scalars("Control_Mean \hspace{0.1cm} Control Mean" "N \hspace{0.1cm} Observations") noobs sfmt(2 %9.0fc 0) compress nostar nobaselevels keep(1.t_invite)
esttab c_took_survey c_r_age c_r_ed_uni c_r_radio_yes c_r_male c_r_ran_before c_r_gov_job_before c_r_adv c_r_NGO c_party_UP c_pref_match_share c_perf_pred using "Table A11.tex", ///
	append nonumber refcat(1.t_invite "\textbf{D. Challengers}", nolabel) ///
	nomtitles b(3) se label alignment(S) f nomtitles nogaps booktabs scalars("Control_Mean \hspace{0.1cm} Control Mean" "N \hspace{0.1cm} Observations") noobs sfmt(2 %9.0fc 0) compress nostar nobaselevels keep(1.t_invite)

esttab took_survey_w1 r_age_w1 r_ed_uni_w1 r_radio_yes_w1 r_male_w1 r_ran_before_w1 r_gov_job_before_w1 r_adv_w1 r_NGO_w1 party_UP_w1 pref_match_share_w1 perf_pred_w1 using "Table A12.tex", ///
	replace nonumber refcat(1.t_invite "\textbf{A. All candidates}", nolabel) ///
	nomtitles posthead("`titles'" "`numbers'") b(3) se label alignment(S) f nomtitles nogaps booktabs scalars("Control_Mean \hspace{0.1cm} Control Mean" "N \hspace{0.1cm} Observations" "Weight \hspace{0.1cm}  Weight") noobs sfmt(2 %9.0fc 0) compress nostar nobaselevels keep(1.t_invite)
esttab c_took_survey_w1 c_r_age_w1 c_r_ed_uni_w1 c_r_radio_yes_w1 c_r_male_w1 c_r_ran_before_w1 c_r_gov_job_before_w1 c_r_adv_w1 c_r_NGO_w1 c_party_UP_w1 c_pref_match_share_w1 c_perf_pred_w1 using "Table A12.tex", ///
	append nonumber refcat(1.t_invite "\textbf{B. Challengers}", nolabel) ///
	nomtitles b(3) se label alignment(S) f nomtitles nogaps booktabs scalars("Control_Mean \hspace{0.1cm} Control Mean" "N \hspace{0.1cm} Observations" "Weight \hspace{0.1cm}  Weight") noobs sfmt(2 %9.0fc 0) compress nostar nobaselevels keep(1.t_invite)


*** Incumbent performance score card measures **********************************
********************************************************************************

cd "$root"
use "Data/data_incumbents.dta"
cd "$output"

foreach var in SC_present SC_absent SC_distant {
	capture quietly eststo `var': areg `var' i.t_invite, absorb(t_block) robust
		qui estadd local Weight "No"
		qui sum `var' if e(sample)==1 & t_invite==0
		qui estadd scalar Control_Mean = `r(mean)'
		qui estadd scalar Control_SD = `r(sd)'
	capture quietly eststo `var'_w1: areg `var' i.t_invite [aweight=wgt_reg], absorb(t_block) robust
		qui estadd local Weight "Reg"	
		qui sum `var' [aweight=wgt_reg] if e(sample)==1 & t_invite==0
		qui estadd scalar Control_Mean = `r(mean)'
}

local titles "& \multicolumn{2}{c}{ \textbf{Attendance} } & \multicolumn{2}{c}{\textbf{Absent}} & \multicolumn{2}{c}{\textbf{Distant}} \\"
local lines "\cmidrule(lr{1em}){2-3} \cmidrule(lr{1em}){4-5} \cmidrule(lr{1em}){6-7} "
local numbers " & (1) & (2) & (3) & (4) & (5) & (6) \\ \midrule"

esttab SC_present SC_present_w1 SC_absent SC_absent_w1 SC_distant SC_distant_w1 using "Table A10.tex", ///
	replace nonumber nomtitles posthead("`titles'" "`lines'" "`numbers'") b(3) se label alignment(S) f nomtitles nogaps booktabs scalars("Control_Mean \hspace{0.1cm}  Control Mean" "N \hspace{0.1cm} Observations" "Weight \hspace{0.1cm} Weight") noobs sfmt(3 %9.0fc 0) compress nostar nobaselevels keep(1.t_invite)

clear all	
